x<template>
  <el-container>
    <el-header height="84px">
      <div class="login-box">
        <!-- <img src="../assets/img/logo.png" alt="" /> -->
        <h1>
          老西门街道店招店牌管理系统
        </h1>
      </div>
      <div class="user-box">
        <el-image class="identify-icon" :src="src1" />
        <el-button type="text" @click="resetPassword()">
          修改密码
        </el-button>
        <span class="split-line"> | </span>
        <el-image class="identify-icon" :src="src2" />
        <el-button type="text" @click="unlogin()">退出登陆</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside class="left-side">
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#EFF4F8"
          text-color="#484848"
          active-text-color="#484848"
          router
        >
          <el-image :src="src"></el-image>
          <div class="welcome-word">欢迎您，{{ this.username }}</div>
          <div class="user-name"></div>
          <el-menu-item index="/shopList"
            ><el-image :src="src_list1"></el-image>店铺基本信息</el-menu-item
          >
          <el-menu-item index="/dangerShopList"
            ><el-image :src="src_list2"></el-image>隐患店招信息</el-menu-item
          >
          <el-menu-item index="/userList"
            ><el-image :src="src_list3"></el-image>用户信息</el-menu-item
          >
        </el-menu>
      </el-aside>
      <el-dialog
        title="修改密码"
        width="20%"
        top="30vh"
        :visible.sync="dialogFormVisible"
        @close="cancelConfirmDialog()"
      >
        <el-form ref="form" :model="form" :rules="resetForm">
          <el-form-item prop="password">
            <el-input
              type="password"
              placeholder="输入密码"
              v-model="form.password"
              autocomplete="off"
              @input="clearErrorInfo()"
            ></el-input>
            <div v-if="errorInfoShow" class="errorInfo">{{ errorInfo }}</div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="confirm()">验 证</el-button>
          <el-button @click="cancelConfirmDialog()">取 消</el-button>
        </div>
      </el-dialog>
      <el-dialog
        title="设置新密码"
        width="20%"
        top="30vh"
        :visible.sync="dialogFormVisible2"
        @close="cancelForgetDialog()"
      >
        <el-form ref="form2" :model="form2" :rules="resetForm2">
          <el-form-item prop="reset">
            <el-input
              type="password"
              placeholder="输入密码"
              v-model="form2.reset"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item prop="conform">
            <el-input
              type="password"
              placeholder="确认密码"
              v-model="form2.conform"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="forget()">提 交</el-button>
          <el-button @click="cancelForgetDialog()">取 消</el-button>
        </div>
      </el-dialog>
      <el-container>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
import qs from "qs";
import { removeToken } from '../utils/auth'
export default {
  data() {
    let validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.form2.reset) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      errorInfoShow: false,
      errorInfo: "",
      disabled: true,
      userData: {},
      username: "",
      imgUrl: "",
      menushow: false, // 控制左侧菜单 折叠true、展开false,
      authorityData: true,
      dialogFormVisible: false,
      dialogFormVisible2: false,
      form: {
        password: ""
      },
      form2: {
        reset: "",
        conform: ""
      },
      resetForm: {
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      },
      resetForm2: {
        reset: [{ required: true, message: "请输入密码", trigger: "blur" }],
        conform: [{ trigger: "blur", validator: validatePass2 }]
      },
      src: require("../assets/img/001_06.png"),
      src1: require("../assets/img/001_13.png"),
      src2: require("../assets/img/001_17.png"),
      src_list1: require("../assets/img/001_03.png"),
      src_list2: require("../assets/img/001_09.png"),
      src_list3: require("../assets/img/001_15.png")
    };
  },
  created() {
    //this.sessionData();
    this.username = this.$store.getters.getUser.user_name;
  },

  methods: {
    clearErrorInfo() {
      if (this.errorInfoShow) {
        this.errorInfoShow = false;
      }
    },
    clickDisabled() {
      if (this.disabled) {
        return this.$message.error("无权限进入,如有需要请联系房管办更改");
      }
    },
    sessionData() {
      const userData = sessionStorage.getItem("userData");
      this.userData = JSON.parse(userData);

      if (this.userData.auth.pp_admin) {
        this.disabled = false;
      }
    },
    resetPassword() {
      this.dialogFormVisible = true;
    },
    confirm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$request({
            url: "rf/modifyPassword",
            method: "post",
            data: qs.stringify({
              username: this.$store.getters.getUser.user_name,
              password: this.form.password
            })
          }).then(response => {
              if (response.error_code == 0) {
                this.dialogFormVisible = false;
                this.dialogFormVisible2 = true;
              } else {
                this.errorInfo = response.error_msg;
                this.errorInfoShow = true;
              }
            })
            .catch(error => {
              this.$message({
                message: "验证失败，网络异常",
                type: "info",
                duration: 2000
              });
            });
        }
      });
    },
    
    cancelConfirmDialog() {
      this.dialogFormVisible = false;
      this.$refs['form'].resetFields();
      this.clearErrorInfo();
    },
    unlogin() {
      this.$confirm("确认要退出系统么?", "退出", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
          //const s = await this.$store.dispatch('setUser',null);
          window.localStorage.removeItem('setUser');
          removeToken();
          this.$router.push("/login");
        })
        .catch(() => {});
    },
    forget() {
      this.$refs.form2.validate(valid => {
        if (valid) {
          this.$request({
            url: "rf/modifyPassword",
            method: "post",
            data: qs.stringify({
              username: this.$store.getters.getUser.user_name,
              newPassword: this.form2.conform
            })
          }).then(response => {
              if (response.error_code == 0) {
                //const s = await this.$store.dispatch('setUser',null);
                window.localStorage.removeItem('setUser');
                removeToken();
                window.localStorage.removeItem("flag");
                window.localStorage.removeItem("username");
                window.localStorage.removeItem("password");
                this.$router.push({ path: "/login" });
              }
            })
            .catch(error => {
              this.$message({
                message: "修改失败，网络异常",
                type: "info",
                duration: 2000
              });
            });
        }
      });
    },
    cancelForgetDialog() {
      this.dialogFormVisible2 = false;
      this.$refs['form2'].resetFields();
    }
  }
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
  overflow-y: auto;
  overflow-x:hidden;
  &::-webkit-scrollbar { width: 0 !important }
  .el-header {
    color: #fff;
    background-color: #0078da;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 84px;
    box-shadow: 0px 0px 3px 0px #040535;
    .login-box {
      h1 {
        font-size: 40px;
        font-family: Reeji-CloudYuanZhun-GBK;
        font-weight: 400;
        color: #ffffff;
        line-height: 36px;
      }
    }
    .user-box {
      display: flex;
      align-items: center;
      .identify-icon {
        width: 20px;
        height: 20px;
        margin-left: 10px;
        margin-top: 6px;
      }
      .el-button {
        color: #fff;
        margin: 5px 10px 0 5px;
        font-size: 22px;
        font-family: Microsoft YaHei;
        font-weight: bold;
      }
      .split-line {
        font-size: 22px;
        color: #4ce8ff;
      }
    }
  }
  .el-container {
    .left-side {
      width: 317px;
    }
    .el-aside {
      background-color: #eff4f8;
      // height: 90vh;
      .el-menu {
        .el-menu-item {
          font-size: 28px;
          text-align: center;
          display: flex;
          align-items: center;
          justify-content: flex-start;
          .el-image {
            width: 34px;
            height: 35px;
            margin: 0 20px;
          }
        }
        .el-menu-item:hover {
          background-color: #dee9f9 !important;
        }
        .is-active {
          background-color: #dee9f9 !important;
        }
      }
      .el-menu-vertical-demo {
        padding-top: 55px;
        .el-image {
          display: block;
          margin: 0 auto;
          width: 84px;
          height: 84px;
        }
        .welcome-word {
          text-align: center;
          font-size: 20px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #484848;
          line-height: 36px;
          margin-top: 10px;
        }
        .user-name {
          text-align: center;
          font-size: 24px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #484848;
          line-height: 36px;
          margin-bottom: 31px;
        }
      }
    }
    .el-container {
      .el-header {
        background: #fff;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .el-main {
        background-color: #e5ecfc;
        padding-top: 8px;
        padding-left: 16px;
        padding-right: 17px;
        padding-bottom: 11px;
      }
    }
  }
}

.errorInfo {
  color: #f56c6c;
  font-size: 12px;
  line-height: 1;
  padding-top: 4px;
  position: absolute;
  top: 100%;
  left: 0;
}
</style>
